pub mod api;
mod context;
mod database;
mod utils;

pub(crate) fn into_anyhow<T>(e: T) -> napi_ohos::Error
where
    T: std::fmt::Display,
{
    napi_ohos::Error::new(napi_ohos::Status::GenericFailure, format!("{}", e))
}

pub(crate) fn map_anyhow<T>(e: T) -> napi_ohos::Error
where
    T: std::fmt::Debug,
{
    napi_ohos::Error::new(napi_ohos::Status::GenericFailure, format!("{:?}", e))
}

#[cfg(not(target_family = "wasm"))]
#[napi_ohos::module_init]
fn init() {
    let rt = tokio::runtime::Builder::new_multi_thread()
        .enable_all()
        .worker_threads(20)
        .thread_keep_alive(std::time::Duration::from_secs(60))
        .max_blocking_threads(10)
        .build()
        .unwrap();
    napi_ohos::bindgen_prelude::create_custom_tokio_runtime(rt);
}
